package com.dci.controller;

import com.dci.context.Config;
import com.dci.dto.XtgOgzLevelDto;
import com.dci.param.XtgOgzParam;
import com.dci.result.JsonData;
import com.dci.result.ResultInfo;
import com.dci.result.ResultUtil;
import com.dci.service.XtgOgzService;
import com.dci.service.XtgTreeService;
import com.dci.util.BeanValidator;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * All rights Reserved, Designed By 姑苏区政府大数据中心
 *
 * @version V1.0
 * @Title: null.java
 * @Package com.dci.controller
 * @Description: 组织机构管理
 * @author: 张星亮
 * @date: 2019/2/25
 * @Copyright: 2019 姑苏区政府大数据中心. All rights reserved.
 * 注意：本内容仅限于姑苏区政府大数据中心内部传阅，禁止外泄以及用于其他的商业目
 */
@Controller
@RequestMapping("/xtg/ogz")
public class XtgOgzController {

    @Resource
    private XtgOgzService xtgOgzService;

    @Resource
    private XtgTreeService xtgTreeService;

    /**
     * 新增机构方法
     *
     * @param xtgOgzParam
     * @return
     * @throws Exception
     */
    @RequestMapping("/save")
    @ResponseBody
    public ResultInfo saveOgz(XtgOgzParam xtgOgzParam) throws Exception {
        // 捕获参数异常
        BeanValidator.check(xtgOgzParam);
        xtgOgzService.save(xtgOgzParam);
        return ResultUtil.createSuccess(Config.MESSAGE, 906, null);
    }

    /**
     * 部门树状结构
     *
     * @return
     */
    @RequestMapping("/tree")
    @ResponseBody
    public JsonData tree() throws Exception {
        List<XtgOgzLevelDto> dtoList = xtgTreeService.ogzTree();
        return JsonData.success(dtoList);
    }

    /**
     * 更新机构方法
     *
     * @param xtgOgzParam
     * @return
     * @throws Exception
     */
    @RequestMapping("/update")
    @ResponseBody
    public ResultInfo updateOgz(XtgOgzParam xtgOgzParam) throws Exception {
        xtgOgzService.update(xtgOgzParam);
        return ResultUtil.createSuccess(Config.MESSAGE, 906, null);
    }

}
